package com.pai4j.client.controller;

import com.pai4j.client.service.SearchService;
import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.helper.SessionHelper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *  搜索服务
 */
@RestController
@RequestMapping("/client-service/search")
public class SearchController {

    @Resource
    private SearchService searchService;

    /**
     * 搜索
     * @param query : 搜索内容
     * @param type: 搜索类型
     * @param page: 页码
     * @param size: 页大小
     * @return
     */
    @GetMapping("/query")
    public PAIPageResponseBeanUtil query(@RequestParam(value = "q", required = false) String query,
                                         @RequestParam(value = "type", required = false) Integer type,
                                         @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                         @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        String userId = SessionHelper.getCurrentUserId();
        return searchService.query(query,type, userId, page, size);
    }


}
